using System;
using System.Collections;
using System.Data.SqlClient;
using System.Text;
using System.Data;

namespace GenerationCode.Utils
{
	/// <summary>
	/// Summary description for Database.
	/// </summary>
	public class Database
	{
		#region fields
		//private const string QUERY = "SELECT table_name FROM information_schema.Tables "
		//												+	"WHERE  (table_type = 'base table' OR table_type = 'VIEW') AND table_name <> 'dtproperties' AND table_name NOT LIKE 'sys%'";
        private const string QUERY = @"
        SELECT table_name FROM
information_schema.Tables WHERE 
 (table_type = 'base table' OR table_type = 'VIEW')
 AND table_name <> 'dtproperties' and table_name<>'sysdiagrams'
order by table_name ASC";


		private string name;
		private string connectionString;		
		#endregion 

		#region constructor
		public Database( string name, string connectionString )
		{
			this.name = name;
			this.connectionString = connectionString;			
		}
		#endregion 

		#region properties
		public string Name {
			get { return this.name; }
		}
		public IList Tables {
			get {
				return this.GetTables();
			}
		}
		#endregion

		#region methods
		private IList GetTables () {
			IList lst = new ArrayList();
			DataTable tb = null;
			try 
			{
				tb = Utility.GetObjects( this.connectionString, QUERY );
				foreach ( DataRow row in tb.Rows ) 
				{
					string tbName = (string) row[0];										
					Table tbl = new Table ( tbName, this.connectionString );
					lst.Add( tbl );
				}				
			} 
			catch ( Exception ex ) 
			{
				throw ex;				
			}				
			return lst;
		}
		#endregion 
	}
}
